import numpy as np
import opuslib

# 定义采样率和声道数
SAMPLE_RATE = 16000
CHANNELS = 1
FRAME_SIZE = int(SAMPLE_RATE * 60 / 1000)  # 每帧 60 毫秒

# 创建 Opus 编码器
encoder = opuslib.Encoder(SAMPLE_RATE, CHANNELS, opuslib.APPLICATION_AUDIO)

def read_pcm_file(file_path: str) -> np.ndarray:
    with open(file_path, 'rb') as f:
        pcm_data = f.read()
    return np.frombuffer(pcm_data, dtype=np.int16)

def split_into_frames(pcm_data: np.ndarray, frame_size: int) -> list:
    return [pcm_data[i:i + frame_size] for i in range(0, len(pcm_data), frame_size)]